<?php
include_once './inc/config_inc.php';
include_once './inc/mysql_inc.php';
include_once './inc/tool_inc.php';
$link=connect();
if(!$user_id=is_login($link)){
	skip('login.php', 'error', '请登录之后再发帖!');exit();
}

if(isset($_POST['submit'])){
	$_POST=escape($link,$_POST);
	$query="insert into content(content,user_id,create_time) values('{$_POST['content']}',$user_id,now())";
	execute($link, $query);
	if(mysqli_affected_rows($link)==1){
		skip('publish.php', 'ok', '发布成功！');exit();
	}else{
		skip('publish.php', 'error', '发布失败，请重试！');exit();
	}
}

$template['title']='发布留言';
$template['css']=array('style/public.css','style/publish.css');
?>
<?php include 'inc/header_inc.php';?>

<!--留言-->
<div id="publish">
	<a>首页</a> &gt; <span>欢迎留言</span>
	<form method="post" action=" " onsubmit="return check()">
		<textarea name="content" class="content" id="content"></textarea>
		<input class="submit" type="submit" name="submit" id="submit" value="发表" style="margin-left: 20px;" />
		<div style="clear:both;"></div>
	</form>
</div>
<script type="text/javascript">
	function check(){
		var c=document.getElementById('content').value;

		if(c===""){
			alert("留言内容不能为空!");
			return false;
		}
	}
</script>

<?php include 'inc/footer_inc.php'?>